// pages/authorization/authorization.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //判断小程序的API，回调，参数，组件等是否在当前版本可用。
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    isHide: true
  },
  getUserProfile: function () {
    var that = this;
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        var avatarUrl = res.userInfo.avatarUrl;
        var nickName = res.userInfo.nickName;
        var gender = res.userInfo.gender;
        wx.login({
          success: function (resData) {
            var datas = {
              nickPhoto: avatarUrl,
              nickName: nickName,
              gender: gender,
              js_code: resData.code
            };
            app.wxRequest('POST', "Index/getUserOpenId", datas, (res) => {
              var code = res.code;
              var userinfo = res.data;
              //console.log(userinfo)
              var uid = userinfo.uid;
              wx.setStorageSync("userInfo", userinfo);
              wx.setStorageSync("uid", uid);
              wx.navigateBack({

              })
            })
          },
          fail: res => {
            console.log("获取用户信息失败", res)
          }
        })
      }
    })
  }
})